package com.ruoyi.bysj.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.bysj.domain.SysMaintain;
import com.ruoyi.bysj.service.ISysMaintainService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 保养管理Controller
 * 
 * @author laow
 * @date 2021-11-12
 */
@RestController
@RequestMapping("/bysj/maintain")
public class SysMaintainController extends BaseController
{
    @Autowired
    private ISysMaintainService sysMaintainService;

    /**
     * 查询保养管理列表
     */
    @PreAuthorize("@ss.hasPermi('bysj:maintain:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysMaintain sysMaintain)
    {
        startPage();
        List<SysMaintain> list = sysMaintainService.selectSysMaintainList(sysMaintain);
        return getDataTable(list);
    }

    /**
     * 导出保养管理列表
     */
    @PreAuthorize("@ss.hasPermi('bysj:maintain:export')")
    @Log(title = "保养管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SysMaintain sysMaintain)
    {
        List<SysMaintain> list = sysMaintainService.selectSysMaintainList(sysMaintain);
        ExcelUtil<SysMaintain> util = new ExcelUtil<SysMaintain>(SysMaintain.class);
        return util.exportExcel(list, "保养管理数据");
    }

    /**
     * 获取保养管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('bysj:maintain:query')")
    @GetMapping(value = "/{maintainId}")
    public AjaxResult getInfo(@PathVariable("maintainId") Long maintainId)
    {
        return AjaxResult.success(sysMaintainService.selectSysMaintainByMaintainId(maintainId));
    }

    /**
     * 新增保养管理
     */
    @PreAuthorize("@ss.hasPermi('bysj:maintain:add')")
    @Log(title = "保养管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysMaintain sysMaintain)
    {
        return toAjax(sysMaintainService.insertSysMaintain(sysMaintain));
    }

    /**
     * 修改保养管理
     */
    @PreAuthorize("@ss.hasPermi('bysj:maintain:edit')")
    @Log(title = "保养管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysMaintain sysMaintain)
    {
        return toAjax(sysMaintainService.updateSysMaintain(sysMaintain));
    }

    /**
     * 删除保养管理
     */
    @PreAuthorize("@ss.hasPermi('bysj:maintain:remove')")
    @Log(title = "保养管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{maintainIds}")
    public AjaxResult remove(@PathVariable Long[] maintainIds)
    {
        return toAjax(sysMaintainService.deleteSysMaintainByMaintainIds(maintainIds));
    }
}
